/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.NetworkManagement.Components;

import Beans.InternalNetworkBean;
import Beans.VirtualResourceBean;

/**
 * This class represents the internal network configuration.
 *
 * @author Angel Sanadinov
 */
public class InternalNetworkConfiguration extends NetworkManagementComponent
{
    private InternalNetworkBean internalNetworkData; //internal network data
    private DHCPServerConfiguration dhcpServer;  //DHCP server data
    private VirtualResourceBean networkData;     //network data from the database

    /**
     * Constructs an internal network configuration using the specified data. <br><br>
     *
     * Used for retrieving data for an existing internal network.
     *
     * @param internalNetwork internal network data
     * @param dhcpServer DHCP server data for the network, if available
     * @param networkData network data from the database
     */
    public InternalNetworkConfiguration(InternalNetworkBean internalNetwork,
                                        DHCPServerConfiguration dhcpServer,
                                        VirtualResourceBean networkData)
    {
        this.internalNetworkData = internalNetwork;
        this.dhcpServer = dhcpServer;
        this.networkData = networkData;
    }

    /**
     * Retrieves the internal network data object.
     *
     * @return the network data
     */
    public InternalNetworkBean getInternalNetworkData() {
        return internalNetworkData;
    }

    /**
     * Retrieves the DHCP server data associated with this internal network.
     *
     * @return the DHCP server data, if available or <code>null</code> otherwise
     */
    public DHCPServerConfiguration getDhcpServer() {
        return dhcpServer;
    }

    /**
     * Retrieves the virtual resource data for the network.
     *
     * @return the network data
     */
    public VirtualResourceBean getNetworkData() {
        return networkData;
    }

    @Override
    public boolean isValid()
    {
        if(internalNetworkData != null && internalNetworkData.isValid()
                && networkData != null && networkData.isValid()
                && (!internalNetworkData.isDHCPAvailable() || (dhcpServer != null && dhcpServer.isValid())))
            return true;
        else
            return false;
    }

    @Override
    public String toString()
    {
        return internalNetworkData.getNetworkName() + "," + internalNetworkData.getNetworkId() + "," + internalNetworkData.isDHCPAvailable();
    }
}
